#!/bin/bash

set -o errexit
set -o nounset

worker_ready() {
    celery -A project.asgi.celery inspect ping
}

until worker_ready; do
    >&2 echo 'Celery workers not available'
    sleep 1
done
>&2 echo 'Celery workers is available'

exec celery flower \
    --persistent=1 \
    --db=/app/flower_db/flower.db \
    --state_save_interval=5000 \
    --app=project.asgi.celery \
    --broker="${CELERY_BROKER_URL}" \
    --basic_auth="${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}"